import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/public/el-table"; //主页面列表
// import CustomDialog from "@/components/reboundStrengthManage/detectionCriteria/index.vue";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置
import actions from "@/actions";
import API from '@/utils/commonRequest.js';

import {
    
    getCheckitemsPageList, //列表

} from "@/api/request.js";
export default {
    name: "detectionCriteria",
    data() {
        return {
            name: "detectionCriteria",
            // 弹框
            showMsgBox: false,
            msgTip: "请先选中数据行！",
            msgType: 1,
            userNature: null, //用户Nature
            // 列表
            getList: {
                modelType: "3",
            },

            isLock: false,
            loading: false,
            btnObj: formJs.btnObj, //按钮
            queryCriteriaData: {}, //分页
            navigatepageNums: null,
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            isShow: false, //是否显示弹框
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            tableData: [],
            // dialogTitle: null,
        };
    },
    computed: {
        hIndex() {
            // 当前页数 - 1 * 每页数据条数 + 1
            return (this.getList.page - 1) * this.getList.pageSize + 1
        }
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        
        // CustomDialog,
 
    },
    mounted() {
        API.userNature().then((res) => {
            if (res.errcode == 0) {
                this.userNature = res.data.Nature;
            }
        }).catch((err) => {
            console.log("API", err)
        })
        actions.onGlobalStateChange((state, prev) => {
            var data = prev.currentUser.projects;
            this.projectsObj = data;
            this.userInfo = prev.currentUser
        }, true);
        // this.yj_searchForm(this.getList);
    },
    methods: {
        // 页面切换
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.getList.page = val;
            this.yj_searchForm(this.getList);
        },
        selectChange(value, index, prop) {
           
            this.getList.modelType = value;
            this.yj_searchForm(this.getList);
        },
      
        refreshList(status) { //刷新列表
            if (status == 0) {
                this.isShow = true;
            }
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        closeDialog() {
            this.isShow = false;
        },

        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 点击查看
        yj_viewForm(row, label) {
            if (label == "标准代号") {
                this.currentRow = row;
                this.$router.push({
                    path: "/reboundStrengthManage/reboundDataDictionary/detectionCriteriaText",
                });
                var data = {
                    data: this.currentRow,
                    getList: this.getList,
                    status: 7,
                    fCompanyid:this.getList.modelType,
                }
                sessionStorage.setItem(
                    "GxEmbedded_primaryInfo",
                    JSON.stringify(data)
                );
            } 
        },
         // 新增/编辑
         yj_edit(num) {
            // if (this.userInfo.userId == 'System') {
                if (num == 7) { //查看
                    if (this.dataFid != null) {
                        this.$router.push({
                            path: "/reboundStrengthManage/reboundDataDictionary/detectionCriteriaText",
                        });
                        var data = {
                            data: this.currentRow,
                            getList: this.getList,
                            status: 7,
                            fCompanyid:this.getList.modelType,
                        }
                        sessionStorage.setItem(
                            "GxEmbedded_primaryInfo",
                            JSON.stringify(data)
                        );

                    } else {
                        this.$message.error({
                            content:"请先选择需要删除的数据",
                            duration: 1000
                        });
                        
                    }
                }
            // } else {
            //     this.$message.warning("该用户无权限");
            // }
        },
        // 查看
        editText() {
            this.isShow = true;
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(data) {
            this.loading = true;
            var that = this;
            getCheckitemsPageList({modelType:data.modelType})
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.checkitemsList.list;
                        that.queryCriteriaData = res.data.checkitemsList; //分页信息
                        that.navigatepageNums =
                            res.data.checkitemsList.navigatepageNums.length;
                    } else {
                        this.$message.error({
                            content:"列表数据获取失败"+res.msg,
                            duration: 1000
                        });
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error({
                        content:"列表数据获取失败"+error.msg,
                        duration: 1000
                    });
                    this.loading = false;
                });
        },
    },
};